<?php
namespace app\common\logic\cast\news;



use app\common\logic\cast\Base;
use app\common\utils\Utils;
use fast\Random;
use think\exception\ValidateException;


/**
 * Created by PhpStorm.
 * User: yangchunfu
 * Date: 2019/12/24
 * Time: 4:36 PM
 * 栏目
 */

class Bilibi extends Base
{
    protected $apiHref = 'http://api01.idataapi.cn:8000/video/bilibili';
    private $cates = [

    ];
    public function __construct($options= [], $tag = 'bilibili')
    {
        $this->cates = config('site.bilibiliconfig');
        $k = array_rand($this->cates, 1);
        $cate_id = $this->cates[$k];
        $options = array_merge([
            'stype' => 4,
            'type' => 'video',
            'catid' => $cate_id
        ], $options);

        parent::__construct($options, $tag);
    }

    /**
     * 获取视频链接
     * id,url,title,publishDate,imageUrls
     */
    public function getField($v) {
        $data['imageUrls'] = isset($v['coverUrl']) ? $v['coverUrl'] : '';
        $data['news_id'] = isset($v['id']) ? 'bibili_'.$v['id'] : MD5($v['url']);
        $data['url'] = isset($v['url']) ? $v['url'] : '';
        $data['title'] = isset($v['title']) ? $v['title'] : '';
        $data['publishDate'] = isset($v['publishDate']) ? $v['publishDate'] : time();
        $data['viewCount'] = isset($v['viewCount']) ? $v['viewCount'] : 0;
        $data['likeCount'] = isset($v['likeCount']) ? $v['likeCount'] : 0;
        $data['commentCount'] = isset($v['commentCount']) ? $v['commentCount'] : 0;
        return $data;
    }



}

